package cn.sc.summer.auth.config;

import cn.sc.summer.auth.filter.AppLoginFilter;
import cn.sc.summer.auth.filter.SmsCodeLoginFilter;
import cn.sc.summer.auth.filter.LoginFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;

/**
 * 类名：过滤器配置类
 *
 * @author a-xin
 * @date 2024/6/29 13:45
 */
@Slf4j
@Configuration
@ConditionalOnBean(value = AuthenticationManager.class)
public class FilterConfig {

    /**
     * 手机号密码登录
     *
     * @return 登录拦截器
     */
    @Bean
    public LoginFilter loginFilter(AuthenticationManager authenticationManager) {
        log.info("==> Loading Sign-in method: {}", "login");
        LoginFilter loginFilter = new LoginFilter();
        loginFilter.setAuthenticationManager(authenticationManager);
        return loginFilter;
    }

    /**
     * 手机号验证码登录
     *
     * @return 登录拦截器
     */
    @Bean
    public SmsCodeLoginFilter smsCodeLoginFilter(AuthenticationManager authenticationManager) {
        log.info("==> Loading Sign-in method: {}", "smsLogin");
        SmsCodeLoginFilter smsCodeLoginFilter = new SmsCodeLoginFilter();
        smsCodeLoginFilter.setAuthenticationManager(authenticationManager);
        return smsCodeLoginFilter;
    }

    /**
     * 小程序登录
     *
     * @return 登录拦截器
     */
    @Bean
    public AppLoginFilter appLoginFilter(AuthenticationManager authenticationManager) {
        log.info("==> Loading Sign-in method: {}", "appLogin");
        AppLoginFilter appLoginFilter = new AppLoginFilter();
        appLoginFilter.setAuthenticationManager(authenticationManager);
        return appLoginFilter;
    }

}
